﻿using ConfExpert.Forms.Base;
using DevTeam;


using System;
using System.Data;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo
{
    public partial class SayimAnaliz : XForm
    {
        public SayimAnaliz()
        {
            InitializeComponent();
        }

        DataTable dt;
        public SayimAnaliz(DataTable _dt)
            :this()
        {
            dt = _dt;
        }

        BindingSource bs0;
        private void SayimAnaliz_Load(object sender, EventArgs e)
        {
            DataSet ds = Session.DataManager.ExecuteDataSet("GetSayimAnaliz", dt.Serialize(), intParse(gle1.EditValue), intParse(gle2.EditValue));
            bs0 = new BindingSource(ds, ds.Tables[0].TableName);
            gv1.Init(ds.Tables[1]);
            gv1.AddDetailGrid(gv2, "SayimId");
            gv3.Init(ds.Tables[3]);
            gv4.Init(ds.Tables[4]);
            gv5.Init(ds.Tables[5]);

            l1.DataBindings.Add("Text", bs0, "v1");
            l2.DataBindings.Add("Text", bs0, "v2");
            l3.DataBindings.Add("Text", bs0, "v3");

            //gv1.FormatAsPercentage("MissedPct1", "MissedPct2");
            gv1.FormatAsNumber(0, "MissedCount1", "MissedCount2", "CompletionTimeInMins");

            gle1.Edit.Assign(RI(Rp.Shelf));
            gle2.Edit.Assign(RI(Rp.Shelf));
            gle1.EditValue = 200;
            gle2.EditValue = 265;

            splitContainerControl1.AutoSize();
            btnAnaliz.ItemClick += btnAnaliz_ItemClick;
            btnAnaliz.PerformClick();
        }

        void btnAnaliz_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (dt != null)
            {
                gv1.RefreshDataSource(true, "GetSayimAnaliz", dt.Serialize(), intParse(gle1.EditValue), intParse(gle2.EditValue));
                gv1.BestFitColumns();
            }
        }
    }
}